(function(){
	var onNew="";
	// 使用http 做客户端（莫伊客户端发送http请求）
	$(".main-pro-home").on("hover",".menuClick",function(event){
		onNew=event.target;
		$(".main-pro-home li").removeClass("mainHover");
	 	$(event.target).addClass("mainHover");
		//  向服务器请求数据  消息协议号 2000  data id
		sendSever(event.target.id,2000,function(res){
			$(".main-pro-info-home").show();
			var str="";
			for (var i = 0; i < res.moreCity.length; i++) {
				if (event.target.id==5) {
					$(".main-pro-info-home").width(390);
						str+="<div class=main-pro-info-city>"
						+"<p class=main-pro-info-title>"
						+res.moreCity[i].cityName
						+"</p><div class=main-pro-info-city-title>";
						for(var j=0;j<res.moreCity[i].items.length;j++){
							str+="<span class=main-pro-info-img style=background-image:url("+res.moreCity[i].items[j]+")></span>"
						}
						str+="</ul></div><div class=main-city></div>";
				}else if (event.target.id==3) {
					str+="<div class=main-info-right>";
					str+="<div class=main-pro-info-city>"
						+"<p class=main-pro-info-title>"
						+res.moreCity[i].cityName
						+"</p><ul class=main-pro-info-city-title>";
					for(var j=0;j<res.moreCity[i].items.length;j++){
						str+="<li>"+res.moreCity[i].items[j]+"</li>"
					}
					str+="</ul></div><div class=main-city></div></div>";
				}else{
					$(".main-pro-info-home").width(700);

					if (i%2==0){
						str+="<div class=main-info-right>"
					}
					str+="<div class=main-pro-info-city>"
						+"<p class=main-pro-info-title>"
						+res.moreCity[i].cityName
						+"</p><ul class=main-pro-info-city-title>";
					for(var j=0;j<res.moreCity[i].items.length;j++){
						str+="<li>"+res.moreCity[i].items[j]+"</li>"
					}
					str+="</ul></div><div class=main-city></div>";
					if (i%2==1){
						str+="</div>"
					}
				}
			}
			if (res.moreCityImg!=undefined) {
				str+="<div class=mian-city-texture style=background-image:url("+res.moreCityImg+")></div></div>"
			};
			$(".main-pro-info-home").html(str);
		});
	 })
	 

	 // 机酒自由行 请球更换数据
	 $(".mian-freedom-play-title").on("hover","a",function(event){
	 	$(".mian-freedom-play-title li a").removeClass("mian-active");
	 	$(event.target).addClass("mian-active");
	 	sendSever(event.target.id,3000,function(res){
	 		console.log(res.data.length);
	 		var str="";
	 		for(var i=0;i<res.data.length;i++){
				if(i==0){
				str+="<div class=main-freedom-one style=background:url("+res.data[i].imgUrl+")>"
					+"<div class=main-plane>"
					+"<span class=main-plane-title>机票</span>"
					+"<span class=main-plane-price>"+res.data[i].price+"<span class=main-plane-price-last>元起</span></span>"
					+"</div><div class=main-freedom-bottom>"
					+"<p  class=main-freedom-def>"+res.data[i].title+"</p>"
					+"<p  class=main-freedom-time>"+res.data[i].time+"</p></div></div>";
				}else{
				str+="<div class=main-freedom-other style=background-image:url("+res.data[i].imgUrl+")>"
					+"<div class=main-plane main-plane-other>"
					+"<span class=main-plane-title>机票</span>"
					+"<span class=main-plane-price>"+res.data[i].price+"<span class=main-plane-price-last>元起</span></span>"
					+"</div><div class=main-freedom-other-bottom><p>"
					+res.data[i].title+"</p></div></div>"
				}
			}

			str+="<div class='main-freedom-other main-freedom-other-last'>"
					+"<div class=main-freedom-other-last-title>查看更多<br>自由行产品"
					+"</div><p class=main-freedom-other-last-info>"
					+"<span>机票</span><span>机票</span><span>机+酒</span>"
					+"<span>机票</span></p></div><div class=main-city></div>";

			$(".main-freedom-home").html(str);
	 		// mainfreedomHome.innerHTML=str;
	 	});
	 })

	// 隐藏面板
	$(".main-pro-info-home").on("mouseout",function(){
		$(onNew).removeClass("mainHover");
		$(".main-pro-info-home").hide();
	})


	//  发送数据
	function sendSever(tagetId,id,callback){
		$.ajax({
			url:"http://localhost:8080/ajaxR",
			type: "GET",
			data:{id:id,data:tagetId},
			success:function(res){
				callback(res);
			}
		});
	};
})();



